package com.xmb.wechat.view.qq;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Color;
import android.support.constraint.Group;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.xmb.wechat.R;
import com.xmb.wechat.R2;
import com.xmb.wechat.base.BaseActivity;
import com.xmb.wechat.bean.WechatContactBean;
import com.xmb.wechat.bean.WechatMsgBean;
import com.xmb.wechat.util.AliPayDateUtils;
import com.xmb.wechat.util.MoneyFormat;
import com.xmb.wechat.util.PicLoadUtils;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * @Author lijiangop
 * @CreateTime 2020/6/1 09:12
 */
public class QQRedPacketDetailActivity extends BaseActivity {

    @BindView(R2.id.tv_remark)
    TextView  mTvRemark;
    @BindView(R2.id.tv_top_money)
    TextView  mTvTopMoney;
    @BindView(R2.id.tv_top_money_tag)
    TextView  mTvTopMoneyTag;
    @BindView(R2.id.iv_avatar)
    ImageView mIvAvatar;
    @BindView(R2.id.tv_avatar)
    TextView  mTvAvatar;
    @BindView(R2.id.tv_desc)
    TextView  mTvDesc;
    @BindView(R2.id.gp_un_receive_from_me)
    Group     mGpUnReceiveFromMe;
    @BindView(R2.id.iv_receiver)
    ImageView mIvReceiver;
    @BindView(R2.id.tv_receiver)
    TextView  mTvReceiver;
    @BindView(R2.id.tv_receiver_time)
    TextView  mTvReceiverTime;
    @BindView(R2.id.tv_receiver_money)
    TextView  mTvReceiverMoney;
    @BindView(R2.id.gp_received)
    Group     mGpReceived;
    @BindView(R2.id.gp_received_from_other)
    Group     mGpReceivedFromOther;

    public QQRedPacketDetailActivity() {
        super(R.layout.activity_qq_redpacket_detail);
    }


    public static void start(Activity act, WechatContactBean senderContactBean, WechatContactBean receiverContactBean, WechatMsgBean wechatMsgBean) {
        Intent it = new Intent(act, QQRedPacketDetailActivity.class);
        it.putExtra("wechatMsgBean", wechatMsgBean);
        it.putExtra("sendContactBean", senderContactBean);
        it.putExtra("receiveContactBean", receiverContactBean);
        act.startActivity(it);
    }

    @SuppressLint({"SimpleDateFormat", "SetTextI18n"})
    @Override
    protected void initView() {
        setStatusBarColor(Color.parseColor("#ff2251"));
        WechatMsgBean wechatMsgBean = (WechatMsgBean) getIntent().getSerializableExtra("wechatMsgBean");
        if (wechatMsgBean == null)
            return;
        //通用
        WechatContactBean sendContactBean = (WechatContactBean) getIntent().getSerializableExtra("sendContactBean");
        //头像, 名称, 备注
        PicLoadUtils.setupRoundAvatarIntoImageView(sendContactBean.getAvatarSrc(), sendContactBean.getAvatar(), mIvAvatar);
        mTvRemark.setText(wechatMsgBean.getMoneyRemark());
        mTvAvatar.setText(getNameWithMe(sendContactBean.getName()) + "的红包");
        //选择布局
        String money = MoneyFormat.formatMoney(wechatMsgBean.getMoney());
        if (wechatMsgBean.getMoneySenderID() == -1) {//我发的红包
            if (wechatMsgBean.isReceiveMoney()) {//已领取
                mTvDesc.setText("1个红包, 已领完");
                mGpReceived.setVisibility(View.VISIBLE);
            } else {
                mTvDesc.setText("领取0/1个, 剩余" + money + "元");
                mGpUnReceiveFromMe.setVisibility(View.VISIBLE);
            }
            //接收信息
            WechatContactBean receiveContactBean = (WechatContactBean) getIntent().getSerializableExtra("receiveContactBean");
            PicLoadUtils.setupRoundPicIntoImageView(receiveContactBean.getAvatarSrc(), receiveContactBean.getAvatar(), mIvReceiver);
            mTvReceiver.setText(getNameWithMe(receiveContactBean.getName()));
            mTvReceiverMoney.setText(money + "元");
            mTvReceiverTime.setText(AliPayDateUtils.getMonthDate(wechatMsgBean.getReceiveTime().getTime()));
        } else {
            mTvDesc.setText("1个红包,已领完");
            mTvTopMoney.setText(money);
            mTvTopMoneyTag.setVisibility(View.VISIBLE);
            mGpReceived.setVisibility(View.VISIBLE);
            mGpReceivedFromOther.setVisibility(View.VISIBLE);
            //接收信息
            WechatContactBean receiveContactBean = (WechatContactBean) getIntent().getSerializableExtra("receiveContactBean");
            PicLoadUtils.setupRoundPicIntoImageView(receiveContactBean.getAvatarSrc(), receiveContactBean.getAvatar(), mIvReceiver);
            mTvReceiver.setText(getNameWithMe(receiveContactBean.getName()));
            mTvReceiverMoney.setText(money + "元");
            mTvReceiverTime.setText(AliPayDateUtils.getMonthDate(wechatMsgBean.getReceiveTime().getTime()));
        }
    }

    @OnClick(R2.id.iv_back)
    public void onViewClicked() {
        finish();
    }
}
